package com.ey12.db.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ey12.db.domain.GmManagerLog;

/**
 * Data access object (DAO) for domain model class GmManagerLog.
 * 
 * @see com.ey12.db.domain.GmManagerLog
 * @author MyEclipse Persistence Tools
 */

public class GmManagerLogDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(GmManagerLogDAO.class);
	// property constants
	public static final String OPERATOR = "operator";
	public static final String ACTION = "action";
	public static final String ACT_DATE = "actDate";
	public static final String IP = "ip";
	public static final String IS_LOGIN = "isLogin";

	protected void initDao() {
		// do nothing
	}

	public void saveOrUpdate(GmManagerLog transientInstance) {
		log.debug("saving GmManagerLog instance");
		try {
			getHibernateTemplate().saveOrUpdate(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(GmManagerLog persistentInstance) {
		log.debug("deleting GmManagerLog instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public GmManagerLog findById(java.lang.Integer id) {
		log.debug("getting GmManagerLog instance with id: " + id);
		try {
			GmManagerLog instance = (GmManagerLog) getHibernateTemplate().get(
					"com.ey12.db.domain.GmManagerLog", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(GmManagerLog instance) {
		log.debug("finding GmManagerLog instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding GmManagerLog instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from GmManagerLog as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByOperator(Object operator) {
		return findByProperty(OPERATOR, operator);
	}

	public List findByAction(Object action) {
		return findByProperty(ACTION, action);
	}

	public List findByActDate(Object actDate) {
		return findByProperty(ACT_DATE, actDate);
	}

	public List findByIp(Object ip) {
		return findByProperty(IP, ip);
	}

	public List findByIsLogin(Object isLogin) {
		return findByProperty(IS_LOGIN, isLogin);
	}

	public List findAll() {
		log.debug("finding all GmManagerLog instances");
		try {
			String queryString = "from GmManagerLog";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public GmManagerLog merge(GmManagerLog detachedInstance) {
		log.debug("merging GmManagerLog instance");
		try {
			GmManagerLog result = (GmManagerLog) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(GmManagerLog instance) {
		log.debug("attaching dirty GmManagerLog instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(GmManagerLog instance) {
		log.debug("attaching clean GmManagerLog instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static GmManagerLogDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (GmManagerLogDAO) ctx.getBean("GmManagerLogDAO");
	}
}